package com.tbit.uqbike.push.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author:BUGTian
 * @DATE: 2022/10/10
 */
@Slf4j
@RestController
public class HeartbeatController {

    /**
     * 版本号
     */
    @Value("${geo-version}")
    String version;

    /**
     * 心跳检测
     *
     * @return
     */
    @RequestMapping(value = "/heartbeat")
    public int heartbeat() {
        return 1;
    }

    /**
     * 获取版本号接口
     *
     * @param response
     */
    @GetMapping("/version")
    public void version(HttpServletResponse response) {
        response.setContentType("application/json;charset:utf-8");
        response.setCharacterEncoding("UTF-8");
        response.setStatus(200);
        PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        out.print(version);
        out.flush();
        out.close();
    }
}
